﻿namespace Zero.Common
{
    /// <summary>
    /// Interface marking backend request object.
    /// </summary>
    /// <remarks>
    /// Every object, that implements this interface along with its <typeparamref name="TResponse"/> type will be marked as transport object between frontend and backend.
    /// Also allows strong-typed messaging from frontend to backend.
    /// </remarks>
    /// <typeparam name="TResponse">Type of response object for this request.</typeparam>
    public interface IRequest<TResponse>
    {
    }

    /// <summary>
    /// Strong-typed generic version of <see cref="IBackend"/>.
    /// </summary>
    public interface ITypedBackend
    {
        /// <summary>
        /// Strong-typed generic version of <see cref="IBackend.Process"/>
        /// </summary>
        /// <typeparam name="TResponse"></typeparam>
        /// <param name="request"></param>
        /// <returns></returns>
        TResponse Process<TResponse>(IRequest<TResponse> request);
    }

    /// <summary>
    /// Represents backend to process requests from frontend.
    /// </summary>
    /// <seealso cref="IRequest{TResponse}"/>
    /// <seealso cref="ITypedBackend"/>
    public interface IBackend
    {
        /// <summary>
        /// Processes specific request from frontend.
        /// </summary>
        /// <param name="request">Request object.</param>
        /// <returns>Response object.</returns>
        object Process(object request);
    }
}
